﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace StyleMVVM.View.Impl
{
	public class ImageAdorner : Adorner
	{
		private Image newImage = null;

		public ImageAdorner(UIElement adornedElement, Uri imageUri) :
			base(adornedElement)
		{
			newImage = new Image
				           {
				           };

			System.IO.Stream stream;
			System.Reflection.Assembly assembly;
			System.Drawing.Image bitmap;

			assembly = GetType().Assembly;
			stream = assembly.GetManifestResourceStream("StyleMVVM.Images.Asterisk.png");
			PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None);

			newImage.Source = decoder.Frames[0];
		}

		protected override Visual GetVisualChild(int index)
		{
			return newImage;
		}

		protected override int VisualChildrenCount
		{
			get { return 1; }
		}

		protected override Size ArrangeOverride(Size finalSize)
		{
			newImage.Arrange(new Rect(finalSize.Width, 0, newImage.DesiredSize.Width, newImage.DesiredSize.Height));

			return finalSize;
		}
	}
}